/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("ReportLossDto",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using WareHouse.Write.System.IServices;
using Microsoft.AspNetCore.Authorization;
using SqlSugar;

namespace WareHouse.Write.System.Controllers
{
    public partial class ReportLossDtoController
    {
        private readonly IReportLossDtoService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;
        public readonly ISqlSugarClient _db;

        [ActivatorUtilitiesConstructor]
        public ReportLossDtoController(
            IReportLossDtoService service,
            IHttpContextAccessor httpContextAccessor,
            ISqlSugarClient db
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
            _db = db;
        }
        [HttpPost, Route("Adds"), AllowAnonymous]
        public IActionResult Adds([FromBody] ReportLossDto fieldsToSend)
        {
            var dto = new ReportLossDto()
            {
                Batch = fieldsToSend.Batch,
                IsDel = 0,
                MakeupPeople = fieldsToSend.MakeupPeople,
                MakeupTime = fieldsToSend.MakeupTime,
                OrderId = fieldsToSend.OrderId,
                Price = fieldsToSend.Price,
                ProductCode = fieldsToSend.ProductCode,
                ProductId = fieldsToSend.ProductId,
                ProductName = fieldsToSend.ProductName,
                ProductSKU = fieldsToSend.ProductSKU,
                Remark = fieldsToSend.Remark,
                Number = fieldsToSend.Number,
                ReportLossId = Guid.NewGuid().ToString(),
                ReportLossinfodtoId = Guid.NewGuid().ToString(),
                ReportLossType = fieldsToSend.ReportLossType,
                Warehouse = fieldsToSend.Warehouse
            };
            return Ok(_db.Insertable(dto).ExecuteCommand());
        }
    }
}
